package com.yuyue.note02.controller;

import com.yuyue.note01.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
public class Controller02 {

    //新增，使用method判断请求方式
    @RequestMapping(value = "users",method = RequestMethod.POST)
    @ResponseBody
    public String save(@RequestBody User user){
        System.out.println(RequestMethod.POST + "请求方式，保存User ： " + user);
        return "收到！";
    }

    //修改，使用method判断请求方式
    @RequestMapping(value = "users", method = RequestMethod.PUT)
    @ResponseBody
    public String update(@RequestBody User user){
        System.out.println(RequestMethod.PUT + "请求方式，修改User ： " + user);
        return "收到！";
    }

    //删除，使用路径变量
    @RequestMapping(value = "users/{id}", method = RequestMethod.DELETE)
    @ResponseBody
    public String delete(@PathVariable String id){
        System.out.println(RequestMethod.DELETE + "请求方式，通过id "+ id +" 删除");
        return "收到！";
    }

    //更加id查询
    @RequestMapping(value = "users/{id}", method = RequestMethod.GET)
    @ResponseBody
    public String query(@PathVariable String id){
        System.out.println(RequestMethod.GET + "请求方式，通过id "+ id +" 查询");
        return "收到！";
    }
}
